package com.example.wuqujingdianphone.fragment.mainfragment;

import android.os.Bundle;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.example.wuqujingdianphone.R;
import com.example.wuqujingdianphone.adapter.BookShopPagerAdapter;
import com.example.wuqujingdianphone.fragment.bookcity.BCMultiMediaFragment;
import com.example.wuqujingdianphone.fragment.bookcity.BookCityBookFragment;
import com.example.wuqujingdianphone.fragment.bookcity.BookCityHomeFragment;
import com.example.wuqujingdianphone.fragment.bookcity.WebViewFragment;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;
import butterknife.ButterKnife;
import butterknife.Unbinder;

/**
 * Created by yuanpk on 2018/4/9.
 */

public class BookShopFragment extends Fragment {
    private static final String TAG = "BookShopFragment";
    @BindView(R.id.tabLayout)
    TabLayout mTabLayout;
    @BindView(R.id.viewPager)
    ViewPager mViewPager;
    Unbinder unbinder;


    private BookShopPagerAdapter mShopPagerAdapter;

    public static BookShopFragment getBookShopFragment() {
        BookShopFragment fragment = new BookShopFragment();
        return fragment;
    }

    @Override
    public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_book_shop, container, false);
        TextView textView = (TextView) getActivity().findViewById(R.id.title);
        textView.setText("书城");
        unbinder = ButterKnife.bind(this, view);
        initView();
        return view;
    }

    private void initView() {
        Log.i(TAG, "initView: ");

        mShopPagerAdapter = new BookShopPagerAdapter(getChildFragmentManager(), getTitles(), getFragment());
        mViewPager.setAdapter(mShopPagerAdapter);
        mTabLayout.setupWithViewPager(mViewPager);


    }

    private List<String> titleList;

    private List<String> getTitles() {
        titleList = new ArrayList<>();
        titleList.add("首页");//0
        titleList.add("阅享馆");//图书1
        titleList.add("听书馆");//听书2
        titleList.add("期刊馆");//期刊3
        titleList.add("日习馆");//报纸4
        titleList.add("体验馆");//视频5
        titleList.add("书友会");//6
        return titleList;
    }

    private List<Fragment> getFragment() {

        List<Fragment> fragmentList = new ArrayList<>();
       /* for (int i = 0; i < titleList.size(); i++) {

        }*/
        fragmentList.add(BookCityHomeFragment.getBookCityHomeFragment());
        fragmentList.add(BookCityBookFragment.getBookCityBookFragment());
        fragmentList.add(BCMultiMediaFragment.getBCMultiMediaFragment("听书馆"));
        fragmentList.add(WebViewFragment.getWebViewFragment("期刊馆"));
        fragmentList.add(WebViewFragment.getWebViewFragment("日习馆"));
        fragmentList.add(BCMultiMediaFragment.getBCMultiMediaFragment("体验馆"));
        fragmentList.add(WebViewFragment.getWebViewFragment("书友会"));
        return fragmentList;

    }


    @Override
    public void onDestroyView() {
        super.onDestroyView();
        unbinder.unbind();
    }
}




